package com.hzyl.famousreader.view.widget.core;

import com.blankj.utilcode.util.SPUtils;
import com.hzyl.famousreader.view.widget.core.animation.AnimModeEnum;

/**
 * 阅读配置管理
 */
public class ReadSettingManager {

  /**
   * 主题
   */
  public static final String READ_THEME = "read_theme";

  /**
   * 亮度
   */
  public static final String READ_BRIGHTNESS = "read_brightness";

  /**
   * 是否跟随系统亮度
   */
  public static final String READ_IS_BRIGHTNESS_AUTO = "read_is_brightness_auto";

  /**
   * 文字大小
   */
  public static final String READ_TEXT_SIZE = "read_text_size";

  /**
   * 默认文字大小
   */
  public static final int DEFAULT_READ_TEXT_SIZE = 42;

  /**
   * 是否使用默认的字体大小
   */
  public static final String READ_IS_TEXT_DEFAULT = "read_text_default";

  /**
   * 翻页模式
   */
  public static final String READ_ANIM_MODE = "read_anim_mode";

  /**
   * 是否夜间模式
   */
  public static final String READ_IS_NIGHT_MODE = "read_is_night_mode";

  public static void setReadTheme(ReadThemeEnum readTheme) {
    SPUtils.getInstance().put(READ_THEME, readTheme.toString());
  }

  public static ReadThemeEnum getReadTheme() {
    String theme = SPUtils.getInstance().getString(READ_THEME, ReadThemeEnum.BG_1.toString());
    return ReadThemeEnum.valueOf(theme);
  }

  public static void setNightMode(boolean isNight) {
    SPUtils.getInstance().put(READ_IS_NIGHT_MODE, isNight);
  }

  public static boolean isNightMode() {
    return SPUtils.getInstance().getBoolean(READ_IS_NIGHT_MODE, false);
  }

  public static int getBrightness() {
    return SPUtils.getInstance().getInt(READ_BRIGHTNESS, 40);
  }

  public static void setBrightness(int progress) {
    SPUtils.getInstance().put(READ_BRIGHTNESS, progress);
  }

  public static void setAutoBrightness(boolean isAuto) {
    SPUtils.getInstance().put(READ_IS_BRIGHTNESS_AUTO, isAuto);
  }

  public static boolean isBrightnessAuto() {
    return SPUtils.getInstance().getBoolean(READ_IS_BRIGHTNESS_AUTO, false);
  }

  public static void setTextSize(int textSize) {
    SPUtils.getInstance().put(READ_TEXT_SIZE, textSize);
  }

  public static int getTextSize() {
    return SPUtils.getInstance().getInt(READ_TEXT_SIZE, DEFAULT_READ_TEXT_SIZE);
  }

  public static boolean isDefaultTextSize() {
    int textSize = getTextSize();
    return DEFAULT_READ_TEXT_SIZE == textSize;
  }

  public static void setAnimMode(AnimModeEnum mode) {
    SPUtils.getInstance().put(READ_ANIM_MODE, mode.toString());
  }

  public static AnimModeEnum getAnimMode() {
    String mode = SPUtils.getInstance().getString(READ_ANIM_MODE, AnimModeEnum.COVER.toString());
    return AnimModeEnum.valueOf(mode);
  }
}
